Uec3.roleTemplateOperationModule = Ext.extend(Ext.app.Module, {
    id: 'roleTemplate_operation',
    objsCollection:new Ext.util.MixedCollection(true),
    getObjByKey:function(key){
		return this.objsCollection.get(key);
	},
	view:function(id){
		var desktop =Uec3.App.getDesktop(); 
		desktop.launchWindowByParam("roleTemplate_operation",{id:id,winId:id}); 
	},
    getPanel:function(params) {
   	var module=this;
   	var checkedTree=new Ext.util.MixedCollection();
   	var notCheckedTree=new Ext.util.MixedCollection();
   	var ajax=new Ext.data.Connection();
   	var count=0;
   	Ext.util.Observable.capture(ajax,function(e,conn,b,c){
		if(e=='beforerequest'){
			Ext.MessageBox.show({
                title : "提示",
                msg : "保存中,请稍后.....",
                buttons: false,
                closable:false,
                width:200,
                wait:true,
                modal:true,
                minWidth: this.minProgressWidth
              
            });
		}else if(e=='requestcomplete'||e=='requestexception'){
			Ext.MessageBox.hide();
			if(e=='requestexception')Ext.Msg.alert("警告",'保存失败,网络延迟或断网,请稍后重写打开');
		}
	});
   	var admin_store_data=[{
   		value:1,
   		name:'是'
   		},
   		{
   		value:0,
   		name:'否'
   		}
   	]
   	var admin_store = new Ext.data.JsonStore({
        fields: ['value', 'name'],
        data : admin_store_data
    });
    var isEdit_combo = new Ext.form.ComboBox({
        store: admin_store,
        displayField:'name',
        typeAhead: true,
        hiddenName:'editable',
        mode: 'local',
        fieldLabel:"是否可编辑",
        valueField : 'value',
        forceSelection: true,
        triggerAction: 'all',
        emptyText:'请选择......',
        selectOnFocus:true
    });
    
    var admin_combo = new Ext.form.ComboBox({
        store: admin_store,
        displayField:'name',
        hiddenName:'isAdministrator',
        typeAhead: true,
        mode: 'local',
        fieldLabel:"是否管理员",
        valueField : 'value',
        forceSelection: true,
        triggerAction: 'all',
        emptyText:'请选择......',
        selectOnFocus:true
    });

  	var topPanel=new Ext.FormPanel({
  		  height:60,
	      layout:'form',
	      width:500,
	      border:false,
	      layoutConfig: 
	         {     
	           padding:'5',
			   align:'middle' 
	      },            
	      items:[	
	      	{
	      		xtype:'hidden',
	      		name:'id'
	      	},		             
	        {
	            xtype:'textfield',
	            name:'roleName',
	            width:180,
	            fieldLabel:"角色名称"
	         },
	            admin_combo,
	            isEdit_combo,
	            {
		            layout:"hbox",
		            border:false,
		            layoutConfig: {     
			           padding:'100 0 0 0',
					   align:'middle',
					   pack:'center'
			      	},
			      	items:[	            
			      	new Ext.Button({
		            	text:"保存",
		            	width:60,
		            	iconCls:'icon-save',
		            	handler:function(){
		            		var roleTemplateJson=Ext.encode(encodeFilte(topPanel.getForm().getValues()));
		            		var checkedPreTree=Ext.encode(checkedTree.items);
		            		var unCheckedPreTree=Ext.encode(notCheckedTree.items);
		            		ajax.request({
			 				url:Uec3.App.Constants.homeUrl+'/roleTemplate/base!save.do',
			 				params:{roleTemplateJson:roleTemplateJson,checkedPreTree:checkedPreTree,unCheckedPreTree:unCheckedPreTree},
			 				success:function(response,options){
				 				var result = Ext.decode(response.responseText);
				 				if(result.success=="OK"){
				 					Ext.Msg.alert("信息",'保存成功');
				 				}else{
				 					Ext.Msg.alert("信息",result.success);
				 				}
			 				}
							});
		            	}
		            })]
	            }
	         ]
  	});
  	topPanel.getForm().on('actioncomplete',function(){
  		isHide();
  	});
  	module.objsCollection.add("topPanel",topPanel);
	var tree = new Ext.tree.TreePanel({
        height: 400,
       	width: 300,
        useArrows:true,
        autoScroll:true,
        layout:'form',
        rootVisible: false,
        frame: true,
        root: {
            //id: 'department',
            //expanded:true, 
            //text: '权限角色'
            nodeType: 'async'
        },
        loader: new Ext.tree.TreeLoader({
            dataUrl:Uec3.App.Constants.appUrl+'/roleTemplate/base!getRoleTemplatePermissionList.do',
            baseParams:{roleTemplateId:params.id},
            listeners:{
            	'loadexception':function(tl,node,response){
            		Ext.Msg.alert("错误","加载失败,请重新加载!");
            	},
            	'load':function(){
            		isHide();
            	},
            	'beforeload':function(){
            		var windowLoadMask=module.objsCollection.get('windowLoadMask');
            		if(windowLoadMask)windowLoadMask.show();
            		Ext.MessageBox.show({
	                title : "提示",
	                msg : "加载中,请稍后.....",
	                buttons: false,
	                closable:false,
	                width:200,
	                wait:true,
	                modal:false,
	                minWidth: this.minProgressWidth
	            	});
            	}
            }
        }),
        listeners: {
            'checkchange': function(node, checked){
                if(checked){
                    checkedTree.add(node.attributes.id,node.attributes.id);
                }else{
                    notCheckedTree.add(node.attributes.id,node.attributes.id);
                }
         	}
        }
    });
    tree.expandAll();
    module.objsCollection.add("tree",tree);
	
	var panel=new Ext.Panel({
	    layout: 'column',
	    items: [topPanel,tree]
	});
	
	function isHide(){
		count+=1;
		if(count==2){
			var windowLoadMask=module.objsCollection.get('windowLoadMask');
			if(windowLoadMask)windowLoadMask.hide();
			Ext.MessageBox.hide();
		}
	}
	return panel;
	},
	initEvent:function(params){
		var module=this;
		var win=module.getObjByKey("win");
		var tree=module.getObjByKey("tree");
		var topPanel=module.getObjByKey("topPanel");
		Ext.util.Observable.capture(win,function(e){
	   		if(e=='beforeshow'){
	   			var windowLoadMask=new Ext.LoadMask(win.id);
	   			module.objsCollection.add('windowLoadMask',windowLoadMask);
	   			if(params&&params.id){
	   				topPanel.getForm().load({
	   					url:Uec3.App.Constants.homeUrl+'/roleTemplate/base!getRoleTemplateById.do',
   						params:{id:params.id},
   						success:function(form,action){
   							
   						},
		   				failure:function(){
		        			Ext.Msg.alert("警告",'网络延迟或断网,请稍后重写打开');
						}
	   				});
	   				tree.getLoader().baseParams={roleTemplateId:params.id};
	   			}
	   		}
		});
	},
   createWindow : function(params){
   	  var windowId=this.id;
   	  if(params&&params.winId){
   	  	windowId+="_"+params.winId;
   	  }
      var desktop = Uec3.App.getDesktop();   
      var win = desktop.getWindowByUecId(windowId);
      if(!win){ 
      	 var module=this;
         win = desktop.createWindow({
            uecId: windowId,
            width: 600,
            height: 400,
            title:'权限管理',
            iconCls: 'acc-icon-saleInvoice',
            shim: false,
            moduleObj:module,
            constrainHeader: true,
            maximizable: true,
            layout: "fit", 
            items:[module.getPanel(params)],
            listeners:{
            	'resize':function(win,width,height){
            		var topPanel=this.items.get(0).items.first();
            		var treePanel=this.items.get(0).items.last();
            		var winMinWidth=600;
            		var winMinHeight=400;
            		if(width<winMinWidth||height<winMinHeight){
            		    topPanel.setWidth(width-treePanel.getWidth());
            			win.setWidth(winMinWidth);
            			win.setHeight(winMinHeight);
            			
            		}else{
            			 topPanel.setWidth(width-223);
         				 treePanel.setHeight(height-30);
            		}
            	}
            	/*'show':function(){
            		this.fireEvent('resize');
            	}*/
            }
         });
         module.objsCollection.add("win",win);
         module.initEvent(params);
      } 
      win.show();
   }
});
